﻿using Dict.DataModel;
using UnityEngine;
namespace Story
{
    class StepBase
    {
        protected StoryManager storyManager;

        public EventType eventType;
        public ActionType actionType;
        public string eventParam;
        public string actionParam1;
        public string actionParam2;
        public string actionParam3;
        public void Init(StoryManager storyManager,TableStory stepData)
        {
            this.storyManager = storyManager;

            eventType = (EventType)stepData.eventType;
            actionType = (ActionType)stepData.actionType;
            eventParam = stepData.eventParam;
            actionParam1 = stepData.actionParam1;
            actionParam2 = stepData.actionParam2;
            actionParam3 = stepData.actionParam3;
        }
        
        public void Start()
        {
            this.OnStart();
        }
        public void End()
        {
            storyManager.RunEnd();
        }
        protected virtual void OnStart()
        {
            End();
        }

        #region Help

        public Vector3 GetPosition(string str)
        {
            if (str.Equals("selfPos"))
            {
                return Room.RoomManager.currentRoom.charactorManager.GetSelfCharactor().transform.position;
            }
            var splits = str.Split(',');
            Vector3 v;
            v.x = float.Parse(splits[0]);
            v.y = float.Parse(splits[1]);
            v.z = float.Parse(splits[2]);
            return v;
        }
        public Vector4 GetVector4(string str)
        {
            Vector4 result;
            if (str.Equals("selfPos"))
            {
                var self = Room.RoomManager.currentRoom.charactorManager.GetSelfCharactor();
                var pos = self.transform.position;
                result = new Vector4(pos.x, pos.y, pos.z, self.transform.localEulerAngles.y);
                return result;
            }
            var splits = str.Split(',');
            result.x = float.Parse(splits[0]);
            result.y = float.Parse(splits[1]);
            result.z = float.Parse(splits[2]);
            result.w = float.Parse(splits[3]);
            return result;
        }

        public Room.RoomCharactor GetCharactor(string id)
        {
            if (id.Equals("selfId"))
            {
                return Room.RoomManager.currentRoom.charactorManager.GetSelfCharactor();
            }
            return Room.RoomManager.currentRoom.charactorManager.GetCharactor(id);
        }

        #endregion

    }
}